Repository navigation
fix(js,ts): a standard global a module doesn't import links no other module's export - #3366
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-3238-unimported-globals
branch
from
November 17, 2026 23:33
096c27b to
279b141
Compare
colbymchenry
force-pushed
the
claude/issue-3238-unimported-globals
branch
8 times, most recently
from
November 18, 2026 10:07
bebecfc to
312fa3e
Compare
…module's export
`parseInt(s, 10)` and `new Response('ok')` in a module that neither
declares nor imports the name linked to a project export of that name in
another file, exact-match. A bare name is skipped as a built-in only when it
is on a short list, which has `Date` and `fetch` but not `parseInt`,
`Response`, `URL`, `structuredClone` and the rest, so they fell through to a
project-wide match.
A call or `new` of a standard global (JS_STANDARD_GLOBALS: ECMAScript's, the
web platform's that browsers, Node, Deno and workers share, and the
browser's common constructors) in a JS/TS ES module that doesn't import it
now takes only a candidate in scope: the file's own; a global declaration,
at a script's top level or directly in `declare global`; or a polyfill hung
on the global object (`window.btoa = function btoa…`), the scope reading
PR 2736 gave type names. Only where the name is written bare (`this.set(…)`,
`new ctx.Request(…)` are some object's), no binding holds at the call (a
parameter, a dynamic import's destructured export), the file is a module
(scripts share their top level) and the project doesn't auto-import its
exports (Nuxt, unplugin-auto-import). Any other name keeps the name match as
the fallback the existing tests pin (esm-unexported-binding,
js-function-local-binding, dynamic-import-binding).
Validation:
- js-unimported-global-calls.test.ts: the issue's globals and three more, in
TypeScript and JavaScript, link nothing; a same-file class, an import, a
script polyfill, a `declare global` function and a `window` polyfill still
link, a script still reaches another script's, a dynamic import's
destructured export still links, and a Nuxt app's auto-imported class
still links. Red on main, green here.
- A/B against the 1.6.3 source arm (147fe29, the same kernel): excalidraw
-2 (`new ClipboardItem()` twice, the DOM's, which linked a `Window`
interface property), vscode's src/vs/base + src/vs/editor -2 (a test's
`new File()`, the DOM's, which linked the enum member
`CompletionItemKind.File`), all wrong; fastify, express, ai-chatbot and
taxonomy byte-identical; flask and gin as controls.
Fixes #3238
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
force-pushed
the
claude/issue-3238-unimported-globals
branch
from
November 18, 2026 10:10
312fa3e to
05c228c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A call to a global,
parseInt(s, 10),new Response('ok'),new URL(…),structuredClone(…), in a module that neither declares nor imports the name, linked to a project export of that name in another file (exact-match, 0.9). Reproduced on 1.6.3 and 1.6.2. (1.6.3's #2801 stopped the same when the project's namesake is an interface or a type alias; a class or a function still linked.)Root cause
isBuiltInOrExternalskips a bare JS/TS name only when it is inJS_BUILT_INS, a short list withDateandfetchbut notparseInt,Response,URL,TextEncoderand the rest, so the name fell through to a project-wide match.Fix
A new
JS_STANDARD_GLOBALSlists the standard globals: ECMAScript's, the web platform's that browsers, Node, Deno and workers share (Response,URL,TextEncoder,structuredClone, …), and the browser's common constructors and functions. In the name matcher's candidate pool, and on its fuzzy single-candidate path, a call ornewof one of those in a JS/TS ES module that doesn't import it takes only a candidate in scope, the reading #2736 gave type names:declare global;window.btoa = function btoa(…) {…}.Otherwise the call is the runtime's and links nothing in the project. It applies only where the name is written bare at the reference (
this.set(…)andnew ctx.Request(…), which the extractors record by their last name, are some object's), no binding of the name holds at the call (a parameter, or a destructured one such asimport('./x').then(({ URL }) => new URL(u))), the file is a module (a script shares its top level with other scripts), and the project doesn't auto-import its own exports (Nuxt, unplugin-auto-import).Not
JS_BUILT_INSitself: that list skips resolution outright, so a project's ownclass Eventin the same file would stop linking too.Validation
__tests__/js-unimported-global-calls.test.ts, red on main, green here: the issue's globals and three more, from TypeScript and JavaScript, link nothing; a same-file class, an imported function, a script polyfill, adeclare globalfunction and awindowpolyfill still link; a script still reaches another script's; a dynamic import's destructured export still links; a Nuxt app's auto-imported class still links.new ClipboardItem()twice inclipboard.ts, which linked aWindowinterface property inglobal.d.ts(the global is the DOM's);src/vs/base+src/vs/editor−2: a test'snew File(…), the DOM's, which linked the enum memberCompletionItemKind.File;Left out: the general rule
The issue proposes the import check as the general rule for any bare name, not only a list of globals. I built that first: on the A/B repos it removed only wrong edges, but it contradicts what four existing tests pin on purpose, a name match from an ES module to another module's exported function it doesn't import (
esm-unexported-binding.test.ts,js-function-local-binding.test.ts,dynamic-import-binding.test.tsx2), a fallback for code whose imports the resolver can't see. Changing that policy is a decision for Colby; this PR keeps it for every name but the standard globals.Credit
Thanks @inth3shadows for the report and the diagnosis. (PR #3279 mentions this issue but fixes #3277.)
Fixes #3238
🤖 Generated with Claude Code